<template>
  <el-container>
    <el-header style="background-color:#eff2f7" class="top">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>编辑</el-breadcrumb-item>
        <el-breadcrumb-item>文本编辑</el-breadcrumb-item>
      </el-breadcrumb>
      <!-- header右侧头像开始 -->
      <div class="block">
        <el-avatar :size="50" :src="circleUrl"></el-avatar>
        <div class="poputs">
          <div @click="tzHome">首页</div>
          <div @click="tzLogin">退出</div>
        </div>
      </div>
      <!-- header右侧头像结束 -->
    </el-header>
    <el-main style="background-color:#ffffff" class="main">
      <vue-editor
        id="editor"
        useCustomImageHandler
        @imageAdded="handleImageAdded"
        v-model="editorContent"
      ></vue-editor>
    </el-main>
  </el-container>
</template>
<script>
import { VueEditor } from "vue2-editor";
import axios from "axios";
export default {
  name: "app",
  components: {
    VueEditor,
  },
  data() {
    return {
      editorContent: "Initial Content",
      circleUrl:
        "https://img01.sogoucdn.com/app/a/100520093/fb41c7c77a2454f7-01eba5833e7e38bc-11cc0200d4b834a0dddb28091fd46806.jpg",
    };
  },
  methods: {
    tzHome() {
      this.$router.push({ path: "/home" });
    },
    tzLogin() {
      this.$router.push({ path: "/login" });
    },
    handleImageAdded(file, Editor, cursorLocation) {
      const CLIENT_ID = "993793b1d8d3e2e";

      var formData = new FormData();
      formData.append("image", file);

      axios({
        url: "https://api.imgur.com/3/image",
        method: "POST",
        headers: {
          Authorization: "Client-ID " + CLIENT_ID,
        },
        data: formData,
      })
        .then((result) => {
          console.log(result);
          let url = result.data.data.link;
          Editor.insertEmbed(cursorLocation, "image", url);
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>
<style  scoped>
.block {
  position: relative;
}
.poputs {
  position: absolute;
  top: 55px;
  left: -20px;
  width: 80px;
  height: 60px;
  background-color: #fff;
  box-sizing: border-box;
  box-shadow: 2px 3px 10px -1px #333;
  display: none;
  z-index: 999;
}
.block:hover .poputs {
  display: block;
}
.poputs > div {
  width: 80px;
  height: 30px;
  line-height: 30px;
  text-align: center;
  color: #000;
  cursor: pointer;
}
.poputs > div:hover {
  background-color: #e4e8f1;
  color: #333;
}
/* 编辑框 */
@import "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css";

/* #editor {
  height: 500px;
}
#app {
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
  padding-bottom: 3em;
  margin-top: 50px;
} 
*/
.quillWrapper{
  width: 100%;
  height: 500px;
}
</style>
